package com.codeoss.framework.view.parser;

import org.springframework.stereotype.Service;

import com.codeoss.framework.view.component.Component;
import com.codeoss.framework.view.component.LinkRecord;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

@Service("linkrecordParser")
public class LinkRecordParser extends AbstractComponentParser {
	protected void setAttributes(IParseContext parseContext, ObjectNode objectNode, Component component) {
		super.setAttributes(parseContext, objectNode, component);
		LinkRecord linkRecord = (LinkRecord) component;
		JsonNode jsonNode = objectNode.get("labelExpression");
		if (jsonNode != null) {
			linkRecord.setLabel(jsonNode.asText());
		}

		ObjectNode propertyMapNode = (ObjectNode) objectNode.get("propertyMap");
		if (propertyMapNode != null) {
			jsonNode = propertyMapNode.get("refPageCode");
			if (jsonNode != null) {
				linkRecord.setRefPageCode(jsonNode.asText());
			}
		}

	}

	@Override
	protected Component createComponent(IParseContext parseContext, ObjectNode objectNode) {
		// TODO Auto-generated method stub
		return new LinkRecord();
	}

}
